package com.tarena.day020;

import java.util.Random;//随机数工具

/** 字符演示
 * 字符是一个整数!
 *  */
public class CharDemo {
  public static void main(String[] args) {
    char ch = 65;
    System.out.println(ch);//'A' 默认字符按照人的习惯输出字符
    ch = 20013;
    System.out.println(ch);//中
    ch = '您';//字符字面量
    System.out.println(ch);//您
    System.out.println((int)ch);//'您'字符的unicode编码
    System.out.println((int)'王'); 
    
    System.out.println((int)'A');//65
    System.out.println((int)'B');//66
    System.out.println((int)'C');//67
    System.out.println((int)'D');//68
    System.out.println((int)'E');//69
    System.out.println((int)'F');//70
    
    System.out.println((int)'a');//97
    System.out.println((int)'b');//98
    System.out.println((int)'c');//99
    System.out.println((int)'d');//100
    System.out.println((int)'e');//101
    
    System.out.println((int)'0');//48
    System.out.println((int)'1');//49
    System.out.println((int)'2');//50
    System.out.println((int)'3');//51
    System.out.println((int)'4');//52

    ch = 'A'+1;
    System.out.println(ch);
    Random random = new Random();
    int index = random.nextInt(26);//index = [0,26)
    ch = (char)('A'+index);
    System.out.println(ch); //随机字符 A~Z
    
    int num = '8'-'0';//8
    num = '4'-'0';
    
    ch = '6';
    num = ch-'0';//实现了"数字字符"转换为对应的"数字"
    
    //不是所有字符运算都是有意义的!
    //不是所有字符都能显示!
    ch = 6995;
    System.out.println(ch);
    ch = 7;
    System.out.println(ch);
    System.out.println((int)'\n');
    System.out.println('\u4e2d'); //中
    
  }
}







